from flask import Flask, request

app = Flask(__name__)

"""
请求url
http://127.0.0.1:5000/get?name=hogwarts&password=hogwarts
响应体
{
    "args": {
        "name": "hogwarts",
        "password": "hogwarts"
    },
    "code": "ok"
}
"""


@app.route("/get", methods=['get'])
def get():
    return {
        'args': request.args,
        # 'headers': request.headers,
        'code': 'ok'
    }


"""
请求url：http://127.0.0.1:5000/post
请求json体
{"consignee":"陈瑞123","mobile":"13182452976"}

响应体
{
    "code": "ok",
    "json": {
        "consignee": "陈瑞123",
        "mobile": "13182452976"
    }
}
"""


@app.route('/post/json', methods=['post'])
def post_json():
    return {
        'json': request.json,
        'code': 'ok'
    }


@app.route('/post/form', methods=['post'])
def post_form():
    return {'form': request.form}


if __name__ == '__main__':
    app.run(debug=True)
